<?php
/**
 * Created by PhpStorm.
 * User: Dmitry
 * Date: 28.02.2015
 * Time: 4:38
 */

include_once "Context.php";


function getProducts()
{
    return Context::Prods()->getProducts();
}

function getCurrentProduct($prodId)
{
    $id = $prodId;
    return $result = Context::DB()->query("SELECT * FROM Products WHERE Id = $id");
}


function getMessages(){
    return Context::Prods()->getContacts();
}

function updateProduct($data)
{
    $id = $data["Id"];
    $img = $data["Image"];
    $title = $data["Title"];
    $desc_one = $data["Description_one"];
    $desc_two = $data["Description_two"];
    $desc_three = $data["Description_free"];
    Context::DB()->prepareQuery("UPDATE Products SET Title = '$title', Image = '$img', Description_one =  '$desc_one', Description_two =  '$desc_two', Description_free =  '$desc_three' WHERE  Id = $id");
    return "{result : true}";
}

$method = $_POST['method'];

switch($method)
{
    case 'getprods':
        return getProducts();
    case 'getcurrentprod':
        return getCurrentProduct($_GET['id']);
    case 'GetMessages':
        return getMessages();
    case 'update':
        return updateProduct($_POST['data']);
}

?>

